package com.lsfb.duishangbaos.MoneyManage;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.lsfb.duishangbaos.R;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.OnClick;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;



/**
 * Created by Administrator on 2017/5/9 0009.
 */
@ContentView(R.layout.aty_money_manage)
public class MoneyManageActivity extends LsfbActivity {

    @ViewInject(R.id.money_text1)
    private TextView money_text1;

    @ViewInject(R.id.money_text2)
    private TextView money_text2;

    @ViewInject(R.id.aty_text_money)
    private TextView text_money;

    private int money_type = 1;

    private EarningsMoney earningsMoney;
    private DrawMoney drawMoney;

    /**
     * 用于存储网络数据存储
     */
    private List<Fragment> fragments;

    @Override
    public void initView() {
        //改变系统状态栏颜色
        Window window = this.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ViewGroup decorViewGroup = (ViewGroup) window.getDecorView();
        View statusBarView = new View(window.getContext());
        int statusBarHeight = getStatusBarHeight(window.getContext());
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, statusBarHeight);
        params.gravity = Gravity.TOP;
        statusBarView.setLayoutParams(params);
        statusBarView.setBackgroundColor(getResources().getColor(R.color.color_forgive));
        decorViewGroup.addView(statusBarView);
        if (getIntent().getStringExtra("cash").isEmpty()) {
            text_money.setText("0");
        } else {
            text_money.setText(getIntent().getStringExtra("cash"));
        }


        initFragments();
    }

    /**
     * 计算系统状态栏高度
     *
     * @param context
     * @return
     */
    private int getStatusBarHeight(Context context) {
        int statusBarHeight = 0;
        Resources res = context.getResources();
        int resourceId = res.getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            statusBarHeight = res.getDimensionPixelSize(resourceId);
        }
        return statusBarHeight;
    }

    @Override
    public void initEvent() {

    }

    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.aty_money_back, R.id.aty_homepage_draw_money, R.id.money_btn1, R.id.money_btn2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.aty_money_back:
                finish();
                break;
            //提现
            case R.id.aty_homepage_draw_money:
                startActivity(new Intent(this, DrawMoneyActivity.class));
                break;
            //收益明细
            case R.id.money_btn1:
                money_type = 1;
                money_text1.setTextColor(getResources().getColor(R.color.color_forgive));
                money_text1.setBackground(getResources().getDrawable(R.drawable.frame_down_forgive));
                money_text2.setTextColor(getResources().getColor(R.color.theme_font));
                money_text2.setBackground(getResources().getDrawable(R.drawable.btn_uncheck));
                selectFragment(0);
                break;
            //提现明细
            case R.id.money_btn2:
                money_type = 2;
                money_text1.setTextColor(getResources().getColor(R.color.theme_font));
                money_text1.setBackground(getResources().getDrawable(R.drawable.btn_uncheck));
                money_text2.setTextColor(getResources().getColor(R.color.color_forgive));
                money_text2.setBackground(getResources().getDrawable(R.drawable.frame_down_forgive));
                selectFragment(1);
                break;
        }
    }

    /**
     * 初始化Fragment
     */
    public void initFragments() {
        fragments = new ArrayList<>();
        earningsMoney = new EarningsMoney();
        drawMoney = new DrawMoney();
        fragments.add(earningsMoney);
        fragments.add(drawMoney);
        selectFragment(0);
    }

    /**
     * 选择fragment
     *
     * @param position
     */
    public void selectFragment(int position) {
        getFragmentManager().beginTransaction().replace(R.id.fragment_layout, fragments.get(position)).commit();
    }


    @Override
    public void initData() {

    }
}
